package com.nexus.service.sys.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nexus.core.exception.ServiceException;
import com.nexus.core.service.BaseService;
import com.nexus.core.sys.entity.SysPost;
import com.nexus.core.sys.dto.SysPostDTO;
import com.nexus.core.utils.ObjectUtils;
import com.nexus.service.sys.mapper.SysPostMapper;
import com.nexus.service.sys.service.mapstruct.SysPostWrapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 职务Service
 *
 * @author 路正宁
 * @version 2023-03-16
 */
//@DS("zxhy_platform_db")
@Service
@Transactional(rollbackFor = {ServiceException.class,Exception.class, RuntimeException.class})
public class SysPostService extends BaseService<SysPostMapper, SysPost,SysPostDTO, SysPostWrapper> {

    /**
     * 根据id查询
     *
     * @param id
     * @return
     */
    public SysPostDTO findById(String id) {
        return baseMapper.findById(id);
    }

    /**
     * 自定义分页检索
     *
     * @param page
     * @param queryWrapper
     * @return
     */
    public IPage<SysPostDTO> findPage(Page<SysPostDTO> page, QueryWrapper queryWrapper) {
        queryWrapper.eq("a.deleted", 0); // 排除已经删除
        return baseMapper.findList(page, queryWrapper);
    }

    /**
     * 删除机构关联
     * @Date 2023/9/6 9:51
     * @Author luzhengning
     **/
    public boolean deleteByOrgIds(List<String> orgIds){
        if(ObjectUtils.isEmpty(orgIds))return false;
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.in("sys_org",orgIds);
        return this.remove(queryWrapper);
    }

}
